
/**   
 * 文件名：PermissionListener.java    
 * 版本信息：TRSNMS1.0   
 * 日期：Aug 14, 2012 12:33:29 AM   
 * Copyright Enovell Corporation 2012    
 * 版权所有     
 */

package com.mt.component.listener;

import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.mt.component.context.ContextFactory;

/**
 * 类名称：PropertiesListener <br>
 * 类描述： <br>
 * 创建人： 马腾 <br>
 * 创建时间：Dec 1, 2012 3:54:17 PM <br>
 * 修改人： 马腾 <br>
 * 修改时间：Dec 1, 2012 3:54:17 PM <br>
 */
public class PropertiesListener implements ServletContextListener {
	
	private static Logger logger = Logger.getLogger(PropertiesListener.class);
	
	private Properties messageProperties;
	private Properties configProperties;
	
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		messageProperties = null;
		configProperties = null;
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		ClassLoader classLoader = PropertiesListener.class.getClassLoader();
		try {
			messageProperties = new Properties();
			messageProperties.load(classLoader.getResourceAsStream("message.properties"));
			ContextFactory.getInstance().initMessages(messageProperties);
			
			configProperties = new Properties();
			configProperties.load(classLoader.getResourceAsStream("config.properties"));
			ContextFactory.getInstance().initConfigs(configProperties);
		} catch (Exception e) {
			logger.error("load properties failure,please check your config file for '*.properties'");
			e.printStackTrace();
		}
	}

}
